# Python 2.6.4
# Project Euler, Problem 35
# Copyright 2010 Talha Zaman

def rot(s): return s[1:] + s[0]
#def rotset(s):
#    rots = [s]
#    for j in range(0, len(s)-1):
#        s = rot(s)
#        if s not in rots: rots.append(s)
#    return rots

lim = 1000000
sieve = [0 for i in range(0, lim)]
for i in range(2,lim):
    for j in range(2*i, lim, i):
        sieve[j] += i
primes = [x for x in range(2,lim) if sieve[x]==0]

print "Primes", len(primes)
count = 0
for i in primes:
    s = str(i)
    circular = 1
#    rs = rotset(i)
#    for j in rs:
#        if j not in pri:
#            circular = 0
#            break
    for j in range(0,len(s)-1):
        s = rot(s)
        if int(s) not in primes:
            circular = 0
            break
#    if circular == 1:
#        print i,
#        count += len(rs)
#        for j in rs:
#            pri.remove(j)
    count += circular
print "Circular", count
